package cn.bugstack.domain.strategy.model.valobj;

import cn.bugstack.domain.strategy.service.rule.filter.factory.DefaultLogicFactory;
import cn.bugstack.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Fuzhengwei bugstack.cn @小傅哥
 * @description 抽奖策略规则规则值对象；值对象，没有唯一ID，仅限于从数据库查询对象
 * @create 2024-01-13 09:30
 */
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyAwardRuleModelVO {
    private String ruleModels;
    /**
     * 获取抽奖中规则
     * */

    public String[] raffleBeforeRuleModelList() {
        List<String> ruleModelList = Arrays.stream(ruleModels.split(Constants.SPLIT))
                .filter(DefaultLogicFactory.LogicModel::isBefore)
                .collect(Collectors.toList());
        return ruleModelList.toArray(new String[0]);
    }
    public String[] raffleCenterRuleModelList() {
        List<String> ruleModelList = Arrays.stream(ruleModels.split(Constants.SPLIT))
                .filter(DefaultLogicFactory.LogicModel::isCenter)
                .collect(Collectors.toList());
        return ruleModelList.toArray(new String[0]);
    }


    public String[] raffleAfterRuleModelList() {
        List<String> ruleModelList = Arrays.stream(ruleModels.split(Constants.SPLIT))
                .filter(DefaultLogicFactory.LogicModel::isAfter)
                .collect(Collectors.toList());
        return ruleModelList.toArray(new String[0]);
    }
}
